<script language="JavaScript" type="text/JavaScript">
	var cmd = "";
	var emp_id = "";
	var emp_name = "";
	var pos_id = "";
	var emp_mobile = "";
	var province_id = "";
	var flag_spacial = "";

	var day1 = "";
	var time_b1 = "";
	var time_e1 = "";
	var day2 = "";
	var time_b2 = "";
	var time_e2 = "";
	var day3 = "";
	var time_b3 = "";
	var time_e3 = "";
	var day4 = "";
	var time_b4 = "";
	var time_e4 = "";
	var day5 = "";
	var time_b5 = "";
	var time_e5 = "";
	var day6 = "";
	var time_b6 = "";
	var time_e6 = "";
	var day7 = "";
	var time_b7 = "";
	var time_e7 = "";
	
	//###################### begin action function add, edit, & delete #########################
	function getProvince(){
	    var session = Math.random();
	    new Ajax.Request(
	    "ajax_getprov.php?session=" + session ,			// url
	    { asynchronous: true,			// default is true
	        method: "get",				// default is post
	        onSuccess: function(request) {
	           rtnProv(request.responseText);
	        }
	    });	
	    waiting.innerHTML = '<img src="images/loading1.gif"/> <span class="required">process...</span>';	
	}
	
	function rtnProv(txt){		
		
		var html = '<fieldset><legend class="txt_module_head">เพิ่มข้อมูล</legend>'+
		'<table width="100%" border="0" cellspacing="3" cellpadding="2">'+
		  '<tr>'+
		    '<td width="30%" align="right" class="line_dash" ><span class="txt_module">ชื่อ - นามสกุล</span> : </td>'+
		    '<td class="line_dash">'+				
		        '<input name="emp_name" id="emp_name" type="text" class="textBox_form" />'+
		        '<input name="emp_id" id="emp_id" type="hidden" />  </td>'+		        
		  '</tr>'+
		  '<tr>'+
		    '<td width="30%" align="right" class="line_dash"><span class="txt_module">ตำแหน่ง</span> : </td>'+
		    '<td class="line_dash">'+		
		        '<select name="ls_pos" id="ls_pos" class="combo"><option value="1">Manager</option>'+
		        '<option value="2">Supervisor</option><option value="3">Operator</option>'+		        
		        '<option value="4">Admin</option><option value="5">NOC</option></select></td>'+
		  '</tr>'+
		  '<tr>'+
		    '<td width="30%" align="right" class="line_dash"><span class="txt_module">จังหวัด</span> : </td>'+
		    '<td class="line_dash">'+		
		        '<select name="ls_province" id="ls_province" class="combo">' + txt + '</select></td>'+
		  '</tr>'+
		  '<tr>'+
		    '<td width="30%" align="right" class="line_dash" ><span class="txt_module">มือถือ</span> : </td>'+
		    '<td class="line_dash">'+				
		        '<input name="mobile" id="mobile" type="text" class="textBox_form" />  </td>'+
		  '</tr>'+		 
		  '<tr>'+
		    '<td width="30%" align="right" class="line_dash"><span class="txt_module">Request sms spacial</span> : </td>'+
		    '<td class="line_dash">'+		
		        '<input name="spacial" id="spacial" type="radio" value="Y" /> Y <input name="spacial" id="spacial" type="radio" value="N" /> N </td>'+
		  '</tr>'+		  		   
		  '<tr>'+
		    '<td align="right" >&nbsp;&nbsp;    </td>';		    
		    if(cmd == "add"){
		    	html += '<td ><img src="images/ok-32.png" alt="" width="32" height="19" onclick="cmdEmpName(\'0\',\'add\');" /></td>';
		    }else{
		    	html += '<td ><img src="images/ok-32.png" alt="" width="32" height="19" onclick="cmdEmpName(\'0\',\'edit\');" /></td>';
		    }
		    
		  html += '</tr>'+
		'</table>'+
		'</fieldset>';
		
		emp_add.innerHTML = html;				
		//alert(location_id);
		if(cmd == "edit"){					
			document.getElementById("emp_name").value = emp_name;
			document.getElementById("emp_id").value = emp_id;
			// position								
			var ls_pos = document.getElementById("ls_pos");
			//alert(ls_prov.length);
			for(var i = 0; i < ls_pos.length; i++){
				if(pos_id == ls_pos[i].value){				
					ls_pos[i].selected = true;
					break;
				}
			}
			// province
			var ls_prov = document.getElementById("ls_province");
			//alert(ls_prov.length);
			for(var i = 0; i < ls_prov.length; i++){
				if(province_id == ls_prov[i].value){				
					ls_prov[i].selected = true;
					break;
				}
			}			
			// mobile
			document.getElementById("mobile").value = emp_mobile;	
			//alert(flag_spacial);
			var spacial = document.getElementsByName("spacial");
			for(var i = 0; i < spacial.length; i++){
				if(flag_spacial == spacial[i].value){				
					spacial[i].checked = true;
					break;
				}
			}			
		}//end edit		
		waiting.innerHTML = '';
	}
	
	function actionCmd(command){
		document.getElementById("view_header").style.visibility='visible';
		cmd = command;
		getProvince();		
	}
	
	function actionEdit(empId, empName, pos, prov, mobile, flagsp){
		emp_id = empId;
		emp_name = empName;
		pos_id = pos;
		province_id = prov;
		emp_mobile = mobile;
		//alert(flagsp);
		flag_spacial = flagsp;
		actionCmd("edit");
				
	}
	
	function cmdEmpName(code, cmd){
		//alert(cmd);
		
		if(cmd == "add"){						
			emp_name = document.getElementById("emp_name").value;											
			//position
			var ls_pos = document.getElementById("ls_pos");
			for(var i = 0; i < ls_pos.length; i++){
				if(ls_pos[i].selected == true){				
					pos_id = ls_pos[i].value
					break;
				}
			}
			//province
			var ls_prov = document.getElementById("ls_province");
			for(var i = 0; i < ls_prov.length; i++){
				if(ls_prov[i].selected == true){				
					province_id = ls_prov[i].value
					break;
				}
			}
			emp_mobile = document.getElementById("mobile").value;	
			
			var spacial = document.getElementsByName("spacial");
			//alert(rchk_dup.length);			
			for(var i = 0; i < spacial.length; i++){
				if(spacial[i].checked == true){
					flag_spacial = spacial[i].value;
				}
			}															
					
		}else if(cmd == "del"){
	    	var conf = confirm("ท่านต้องการจะ ลบ ข้อมูลใช่หรือไม่");
	    	if(conf == false){    
	    		return;
	    	}			
			emp_id = code;
		}else if(cmd == "edit"){		
			document.getElementById("emp_id").value = emp_id;	
			emp_name = document.getElementById("emp_name").value;											
			//position
			var ls_pos = document.getElementById("ls_pos");
			for(var i = 0; i < ls_pos.length; i++){
				if(ls_pos[i].selected == true){				
					pos_id = ls_pos[i].value
					break;
				}
			}
			//province
			var ls_prov = document.getElementById("ls_province");
			for(var i = 0; i < ls_prov.length; i++){
				if(ls_prov[i].selected == true){				
					province_id = ls_prov[i].value
					break;
				}
			}
			emp_mobile = document.getElementById("mobile").value;																				
			// flag spacial
			var spacial = document.getElementsByName("spacial");					
			for(var i = 0; i < spacial.length; i++){
				if(spacial[i].checked == true){
					flag_spacial = spacial[i].value;
				}
			}															

		}
		//alert(flag_spacial);
        var session = Math.random();
        new Ajax.Request(
        "ajax_cmdemp.php?session=" + session +'&emp_id=' + emp_id + "&emp_name=" + emp_name + "&pos_id=" + pos_id + "&mobile=" + emp_mobile + "&province_id=" + province_id + "&flagsp=" + flag_spacial + "&action=" + cmd,			// url
        { asynchronous: true,			// default is true
            method: "get",				// default is post
            onSuccess: function(request) {
                rtn(request.responseText);
            }
        });	
		
		waiting.innerHTML = '<img src="images/loading1.gif"/> <span class="required">process...</span>';        		
	}
	
	function rtn(txt){
		view.innerHTML = txt;
		waiting.innerHTML = "";
	}
	
	
	// ============= end action add , delete , add employee ===================================
	
	//#################################### bengn fucntion work day #########################
	function cmdDayWork(empid){
		//alert(empid);
		emp_id = empid;
        var session = Math.random();
        new Ajax.Request(
        "ajax_cmddaywork.php?session=" + session +'&emp_id=' + emp_id + '&action=find',			// url
        { asynchronous: true,			// default is true
            method: "get",				// default is post
            onSuccess: function(request) {
                rtnDayWork(request.responseText);
            }
        });	
		
		waiting.innerHTML = '<img src="images/loading1.gif"/> <span class="required">process...</span>';        		
		
		
	}

	function rtnDayWork(txt){
		document.getElementById("view_header").style.visibility='visible';		
		var html = '<fieldset><legend class="txt_module_head">วันเวลาที่รับ sms</legend>'+
		'<table width="100%" border="0" cellspacing="3" cellpadding="2">'+
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><span class="txt_module">วัน</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><span class="txt_module">เวลาเริ่มต้น</span></td>'+		        
		    '<td width="40%" align="center" class="line_dash"><span class="txt_module">เวลาเริ่มสิ้นสุด</span></td>'+		        
		    
		  '</tr>'+		
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><input type="checkbox" name="day1" checked /><span class="txt_module">วันอาทิตย์</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><input id="time_b1" type="text" class="textBox_time" value="0000" />  </td>'+		        
		    '<td width="40%" align="center" class="line_dash"><input id="time_e1" type="text" class="textBox_time" value="2359"/>  </td>'+		        
		  '</tr>'+
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><input type="checkbox" name="day2" checked /><span class="txt_module">วันจันทร์</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><input id="time_b2" type="text" class="textBox_time" value="0000" />  </td>'+		        
		    '<td width="40%" align="center" class="line_dash"><input id="time_e2" type="text" class="textBox_time" value="2359"/>  </td>'+		        
		  '</tr>'+
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><input type="checkbox" name="day3" checked /><span class="txt_module">วันอังคาร</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><input id="time_b3" type="text" class="textBox_time" value="0000" />  </td>'+		        
		    '<td width="40%" align="center" class="line_dash"><input id="time_e3" type="text" class="textBox_time" value="2359"/>  </td>'+		        
		  '</tr>'+
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><input type="checkbox" name="day4" checked /><span class="txt_module">วันพุทธ</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><input id="time_b4" type="text" class="textBox_time" value="0000" />  </td>'+		        
		    '<td width="40%" align="center" class="line_dash"><input id="time_e4" type="text" class="textBox_time" value="2359"/>  </td>'+		        
		  '</tr>'+
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><input type="checkbox" name="day5" checked /><span class="txt_module">วันพฤหัสบดี</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><input id="time_b5" type="text" class="textBox_time" value="0000" />  </td>'+		        
		    '<td width="40%" align="center" class="line_dash"><input id="time_e5" type="text" class="textBox_time" value="2359"/>  </td>'+		        
		  '</tr>'+
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><input type="checkbox" name="day6" checked /><span class="txt_module">วันศุกร์</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><input id="time_b6" type="text" class="textBox_time" value="0000" />  </td>'+		        
		    '<td width="40%" align="center" class="line_dash"><input id="time_e6" type="text" class="textBox_time" value="2359"/>  </td>'+		        
		  '</tr>'+
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><input type="checkbox" name="day7" checked /><span class="txt_module">วันเสาร์</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><input id="time_b7" type="text" class="textBox_time" value="0000" />  </td>'+		        
		    '<td width="40%" align="center" class="line_dash"><input id="time_e7" type="text" class="textBox_time" value="2359"/>  </td>'+		        
		  '</tr>'+		  
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><img src="images/ok-32.png" alt="" width="32" height="19" onclick="editDayWork();" /></td>'+
		    '<td width="40%" align="center" class="line_dash">&nbsp;</td>'+		        
		    '<td width="40%" align="center" class="line_dash">&nbsp;</td>'+		        
		  '</tr>'+		  		  
		'</table>'+
		'</fieldset>';
		emp_add.innerHTML = html;
		//day1	
		//alert(txt);	
		var oRE = /<day1>(.*)<\/day1>/gi;				
		day1 = rxml(txt, oRE);			
		var cb_day1 = document.getElementsByName("day1");
		if(day1.length == 0 || day1 == "N"){
			cb_day1[0].checked = false;
		}else{
			cb_day1[0].checked = true;
		}
		//alert(txt);	
		oRE = /<time_b1>(.*)<\/time_b1>/gi;				
		time_b1 = rxml(txt, oRE);	
		if(time_b1 == "")time_b1 = "0000";
		document.getElementById("time_b1").value = time_b1;
		oRE = /<time_e1>(.*)<\/time_e1>/gi;				
		time_e1 = rxml(txt, oRE);
		if(time_e1 == "")time_e1 = "2539";
		document.getElementById("time_e1").value = time_e1;
		//day2		
		oRE = /<day2>(.*)<\/day2>/gi;				
		day2 = rxml(txt, oRE);	
		var cb_day2 = document.getElementsByName("day2");
		if(day2.length == 0 || day2 == "N"){
			cb_day2[0].checked = false;
		}else{
			cb_day2[0].checked = true;
		}	
		//alert(txt);	
		oRE = /<time_b2>(.*)<\/time_b2>/gi;				
		time_b2 = rxml(txt, oRE);		
		if(time_b2 == "")time_b2 = "0000";
		document.getElementById("time_b2").value = time_b2;
		oRE = /<time_e2>(.*)<\/time_e2>/gi;				
		time_e2 = rxml(txt, oRE);
		if(time_e2 == "")time_e2 = "2359";
		document.getElementById("time_e2").value = time_e2;
		//day3
		oRE = /<day3>(.*)<\/day3>/gi;				
		day3 = rxml(txt, oRE);				
		var cb_day3 = document.getElementsByName("day3");
		if(day3.length == 0 || day3 == "N"){
			cb_day3[0].checked = false;
		}else{
			cb_day3[0].checked = true;
		}				
		oRE = /<time_b3>(.*)<\/time_b3>/gi;				
		time_b3 = rxml(txt, oRE);		
		if(time_b3 == "")time_b3 = "0000";
		document.getElementById("time_b3").value = time_b3;
		oRE = /<time_e3>(.*)<\/time_e3>/gi;				
		time_e3 = rxml(txt, oRE);
		if(time_e3 == "")time_e3 = "2359";
		document.getElementById("time_e3").value = time_e3;
		//day4
		oRE = /<day4>(.*)<\/day4>/gi;				
		day4 = rxml(txt, oRE);				
		var cb_day4 = document.getElementsByName("day4");
		if(day4.length == 0 || day4 == "N"){
			cb_day4[0].checked = false;
		}else{
			cb_day4[0].checked = true;
		}						
		oRE = /<time_b4>(.*)<\/time_b4>/gi;				
		time_b4 = rxml(txt, oRE);		
		if(time_b4 == "")time_b4 = "0000";
		document.getElementById("time_b4").value = time_b4;
		oRE = /<time_e4>(.*)<\/time_e4>/gi;				
		time_e4 = rxml(txt, oRE);
		if(time_e4 == "")time_e4 = "2359";
		document.getElementById("time_e4").value = time_e4;
		//day5
		oRE = /<day5>(.*)<\/day5>/gi;				
		day5 = rxml(txt, oRE);				
		var cb_day5 = document.getElementsByName("day5");
		if(day5.length == 0 || day5 == "N"){
			cb_day5[0].checked = false;
		}else{
			cb_day5[0].checked = true;
		}
		
		//alert(txt);								
		oRE = /<time_b5>(.*)<\/time_b5>/gi;				
		time_b5 = rxml(txt, oRE);		
		if(time_b5 == "")time_b5 = "0000";
		document.getElementById("time_b5").value = time_b5;
		oRE = /<time_e5>(.*)<\/time_e5>/gi;				
		time_e5 = rxml(txt, oRE);
		if(time_e5 == "")time_e5 = "2359";
		document.getElementById("time_e5").value = time_e5;
		//day6
		oRE = /<day6>(.*)<\/day6>/gi;				
		day6 = rxml(txt, oRE);				
		var cb_day6 = document.getElementsByName("day6");
		if(day6.length == 0 || day6 == "N"){
			cb_day6[0].checked = false;
		}else{
			cb_day6[0].checked = true;
		}										
		oRE = /<time_b6>(.*)<\/time_b6>/gi;				
		time_b6 = rxml(txt, oRE);		
		if(time_b6 == "")time_b6 = "0000";
		document.getElementById("time_b6").value = time_b6;
		oRE = /<time_e6>(.*)<\/time_e6>/gi;				
		time_e6 = rxml(txt, oRE);
		if(time_e6 == "")time_e6 = "2359";
		document.getElementById("time_e6").value = time_e6;
		//day7
		oRE = /<day7>(.*)<\/day7>/gi;				
		day7 = rxml(txt, oRE);				
		var cb_day7 = document.getElementsByName("day7");
		if(day7.length == 0 || day7 == "N"){
			cb_day7[0].checked = false;
		}else{
			cb_day7[0].checked = true;
		}												
		oRE = /<time_b7>(.*)<\/time_b7>/gi;				
		time_b7 = rxml(txt, oRE);		
		if(time_b7 == "")time_b7 = "0000";
		document.getElementById("time_b7").value = time_b7;
		oRE = /<time_e7>(.*)<\/time_e7>/gi;				
		time_e7 = rxml(txt, oRE);
		if(time_e7 == "")time_e7 = "2359";
		document.getElementById("time_e7").value = time_e7;
		
		waiting.innerHTML = "";
		        		
	}
			
	function getParam(){
		var d1 = "";		
		if(document.getElementsByName("day1")[0].checked == true)d1 = "Y";else d1="N";
		var d2 = "";		
		if(document.getElementsByName("day2")[0].checked == true)d2 = "Y";else d2="N";
		var d3 = "";		
		if(document.getElementsByName("day3")[0].checked == true)d3 = "Y";else d3="N";
		var d4 = "";		
		if(document.getElementsByName("day4")[0].checked == true)d4 = "Y";else d4="N";
		var d5 = "";		
		if(document.getElementsByName("day5")[0].checked == true)d5 = "Y";else d5="N";
		var d6 = "";		
		if(document.getElementsByName("day6")[0].checked == true)d6 = "Y";else d6="N";
		var d7 = "";		
		if(document.getElementsByName("day7")[0].checked == true)d7 = "Y";else d7="N";
			
		return "day1=" + d1 +
		"&time_b1=" + document.getElementById("time_b1").value + "&time_e1=" + document.getElementById("time_e1").value +
		"&day2=" + d2 +
		"&time_b2=" + document.getElementById("time_b2").value + "&time_e2=" + document.getElementById("time_e2").value +
		"&day3=" + d3 +
		"&time_b3=" + document.getElementById("time_b3").value + "&time_e3=" + document.getElementById("time_e3").value+
		"&day4=" + d4 +
		"&time_b4=" + document.getElementById("time_b4").value + "&time_e4=" + document.getElementById("time_e4").value+
		"&day5=" + d5 +
		"&time_b5=" + document.getElementById("time_b5").value + "&time_e5=" + document.getElementById("time_e5").value+
		"&day6=" + d6 +
		"&time_b6=" + document.getElementById("time_b6").value + "&time_e6=" + document.getElementById("time_e6").value+
		"&day7=" + d7 +
		"&time_b7=" + document.getElementById("time_b7").value + "&time_e7=" + document.getElementById("time_e7").value;
		
	}
	
	function editDayWork(){
		var param = getParam();
		//alert(param);
		
        var session = Math.random();
        new Ajax.Request(
        "ajax_cmddaywork.php?session=" + session +'&emp_id=' + emp_id + "&" + param + "&action=edit" ,			// url
        { asynchronous: true,			// default is true
            method: "get",				// default is post
            onSuccess: function(request) {
                rtnEditDayWork(request.responseText);
            }
        });	
		
		waiting.innerHTML = '<img src="images/loading1.gif"/> <span class="required">process...</span>';        				
		
	}
	
	function rtnEditDayWork(txt){
		waiting.innerHTML = '<span class="required">sucess...</span>';        				
	}	
	
	
	//#################################### end fucntion work day #########################
	
	//#################################### begin fucntion manage exchange #########################
	var emp_name = "";
	function showExch(empid, empname){
		//alert(province_id);			
		//alert(empname);	
		emp_name = empname;		
		emp_id = empid;		
        var session = Math.random();
        new Ajax.Request(
        "ajax_showexch.php?session=" + session +'&emp_id=' + emp_id + "&empname=" + empname,			// url
        { asynchronous: true,			// default is true
            method: "get",				// default is post
            onSuccess: function(request) {
                rtnShowExch(request.responseText);
            }
        });	
		
		waiting.innerHTML = '<img src="images/loading1.gif"/> <span class="required">process...</span>';      		
	}
	
	
	function rtnShowExch(txt){
		document.getElementById("view_header").style.visibility='visible';	
		//alert(txt);			
		var html_mt = '<fieldset><legend class="txt_module_head">'+ emp_name +' รับผิดชอบ ชุมสาย</legend>' +
		txt + '</fieldset>';	
		//alert(html_mt);		
		emp_add.innerHTML = html_mt;
		waiting.innerHTML = '';      		
	}
	
	function cmdExch(empid, empname, flagsp){
		emp_id = empid;		
		//alert(flagsp);
		document.getElementById("view_header").style.visibility='visible';	
		/*var html_alarm = '<fieldset><legend class="txt_module_head">'+ empname +' ALarm ที่รับ</legend>' +
		'{REQUEST_ALARM}' + '</fieldset>';*/	
		var html_mt = '<fieldset><legend class="txt_module_head">'+ empname +' รับผิดชอบ ชุมสาย</legend>' +
		'{MAINTERNANCE}' + '</fieldset>';
		/*if(flagsp == 'Y'){
			html_mt = html_alarm + html_mt;
		}*/
		emp_add.innerHTML = html_mt;
	}
	
	function getExch(){
		//alert('run getExch');
		//province
		var ls_prov = document.getElementById("ls_provexch");
		for(var i = 0; i < ls_prov.length; i++){
			if(ls_prov[i].selected == true){				
				province_id = ls_prov[i].value
				break;
			}
		}
		
		//alert(province_id);		
        var session = Math.random();
        new Ajax.Request(
        "ajax_getexch.php?session=" + session +'&province_id=' + province_id ,			// url
        { asynchronous: true,			// default is true
            method: "get",				// default is post
            onSuccess: function(request) {
                rtnGetExch(request.responseText);
            }
        });	
		
		waiting.innerHTML = '<img src="images/loading1.gif"/> <span class="required">process...</span>';        				
		
	}
	
	var valueOld = "";
	var cChoice = 0;
	var tail = "";
	var head = "";	
	var empOld = "";
	function rtnGetExch(txt){
		//alert(txt);
		//document.getElementById("showExch");		
		if(cChoice == 0){
			head = '<table width="100%" border="0" cellspacing="3" cellpadding="2">';
			//tail = '<tr><td><img src="images/ok-32.png" alt="" width="32" height="19" onclick="editExch();" /></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr></table>';
			tail = '</table><div id="test1"></div>';
			cChoice++;
		}
		//alert(head + valueOld + txt + tail);	
		//alert(empOld + "old");
		//alert(emp_id + "current");	
		if(empOld == emp_id){
			//alert(head + valueOld + txt + tail);
			test1.innerHTML = head + valueOld + txt + tail;	
			//test1.innerHTML = "ssss";
		}else{
			//alert(head + txt + tail);
			test1.innerHTML = head + txt + tail;	
			//test1.innerHTML = "dddddd";
		}
		
		valueOld += txt;       		
		waiting.innerHTML = '';
		empOld = emp_id; 
	}
	
	function editExch(){
		var val = "";
		var cb_loc = document.getElementsByName("location");
		//alert(cb.loc.length);
		//alert(rchk_dup.length);			
		for(var i = 0; i < cb_loc.length; i++){
			if(cb_loc[i].checked == true){
				val += cb_loc[i].value + '@@';
			}
		}	
		var manager = "";
		var supervisor = "";
		//manager
		var ls_m = document.getElementById("manager");
		for(var i = 0; i < ls_m.length; i++){
			if(ls_m[i].selected == true){				
				manager = ls_m[i].value
				break;
			}
		}

		//supervisor
		var ls_m = document.getElementById("supervisor");
		for(var i = 0; i < ls_m.length; i++){
			if(ls_m[i].selected == true){				
				supervisor = ls_m[i].value
				break;
			}
		}						
		val = val.substr(0, val.length-2);
        var session = Math.random();
        new Ajax.Request(
        "ajax_mmt.php?session=" + session +'&manager=' + manager + "&supervisor=" + supervisor + "&operator=" + emp_id + "&location=" + val ,			// url
        { asynchronous: true,			// default is true
            method: "get",				// default is post
            onSuccess: function(request) {
                rtnMmt(request.responseText);
            }
        });	
        waiting.innerHTML = '<img src="images/loading1.gif"/> <span class="required">process...</span>';
		
	}	
	
	function rtnMmt(txt){
		waiting.innerHTML = '<span class="required">sucess...</span>'; 
		  
	}
	
	//#################################### end fucntion manage exchange #########################	
	
	//#################################### begin fucntion manage Alarm #########################	
	function showALarm(empid, empname){
		emp_id = empid;
		emp_name = empname;
	    var session = Math.random();
	    new Ajax.Request(
	    "ajax_getalarm.php?session=" + session + "&empid=" + emp_id,			// url
	    { asynchronous: true,			// default is true
	        method: "get",				// default is post
	        onSuccess: function(request) {
	           rtnALarm(request.responseText);
	        }
	    });	
	    waiting.innerHTML = '<img src="images/loading1.gif"/> <span class="required">process...</span>';		
	}
	
	function rtnALarm(txt){
		document.getElementById("view_header").style.visibility='visible';			
		var html_mt = '<fieldset><legend class="txt_module_head">'+ emp_name +' ต้องการรับ ALarm</legend>' +
		'<table width="100%" border="0" cellspacing="3" cellpadding="2">'+
		  '<tr>'+
		    '<td width="30%" align="right" class="line_dash"><span class="txt_module">ALarm Description</span> : </td>'+
		    '<td class="line_dash">'+		
		        '<select name="ls_alarm" id="ls_alarm" class="combo_240" onchange="dayAlarm();">' + txt + '</select></td>'+
		  '</tr></table><div id="showDayAlarm"></div>'+
		'</fieldset>';	
		//alert(html_mt);		
		emp_add.innerHTML = html_mt;
		waiting.innerHTML = '';    		
		waiting.innerHTML = ''; 
	}
	var alarm_num = "";
	function dayAlarm(){		
		var ls_alarm = document.getElementById("ls_alarm");
		for(var i = 0; i < ls_alarm.length; i++){
			if(ls_alarm[i].selected == true){				
				alarm_num = ls_alarm[i].value
				break;
			}
		}		
		//alert(emp_id);
		
		
        var session = Math.random();
        new Ajax.Request(
        "ajax_cmddayalarmemp.php?session=" + session +'&emp_id=' + emp_id + '&alarm_num=' + alarm_num + '&action=find',			// url
        { asynchronous: true,			// default is true
            method: "get",				// default is post
            onSuccess: function(request) {
                rtnDayAlarm(request.responseText);
            }
        });	
		
		waiting.innerHTML = '<img src="images/loading1.gif"/> <span class="required">process...</span>';        		
		
	}
	
	function rtnDayAlarm(txt){
		document.getElementById("view_header").style.visibility='visible';		
		var html = '<fieldset><legend class="txt_module_head">วันเวลาที่รับ sms</legend>'+
		'<table width="100%" border="0" cellspacing="3" cellpadding="2">'+
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><span class="txt_module">วัน</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><span class="txt_module">เวลาเริ่มต้น</span></td>'+		        
		    '<td width="40%" align="center" class="line_dash"><span class="txt_module">เวลาเริ่มสิ้นสุด</span></td>'+		        
		    
		  '</tr>'+		
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><input type="checkbox" name="day1" checked /><span class="txt_module">วันอาทิตย์</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><input id="time_b1" type="text" class="textBox_time" value="0000" />  </td>'+		        
		    '<td width="40%" align="center" class="line_dash"><input id="time_e1" type="text" class="textBox_time" value="2359"/>  </td>'+		        
		  '</tr>'+
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><input type="checkbox" name="day2" checked /><span class="txt_module">วันจันทร์</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><input id="time_b2" type="text" class="textBox_time" value="0000" />  </td>'+		        
		    '<td width="40%" align="center" class="line_dash"><input id="time_e2" type="text" class="textBox_time" value="2359"/>  </td>'+		        
		  '</tr>'+
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><input type="checkbox" name="day3" checked /><span class="txt_module">วันอังคาร</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><input id="time_b3" type="text" class="textBox_time" value="0000" />  </td>'+		        
		    '<td width="40%" align="center" class="line_dash"><input id="time_e3" type="text" class="textBox_time" value="2359"/>  </td>'+		        
		  '</tr>'+
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><input type="checkbox" name="day4" checked /><span class="txt_module">วันพุทธ</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><input id="time_b4" type="text" class="textBox_time" value="0000" />  </td>'+		        
		    '<td width="40%" align="center" class="line_dash"><input id="time_e4" type="text" class="textBox_time" value="2359"/>  </td>'+		        
		  '</tr>'+
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><input type="checkbox" name="day5" checked /><span class="txt_module">วันพฤหัสบดี</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><input id="time_b5" type="text" class="textBox_time" value="0000" />  </td>'+		        
		    '<td width="40%" align="center" class="line_dash"><input id="time_e5" type="text" class="textBox_time" value="2359"/>  </td>'+		        
		  '</tr>'+
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><input type="checkbox" name="day6" checked /><span class="txt_module">วันศุกร์</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><input id="time_b6" type="text" class="textBox_time" value="0000" />  </td>'+		        
		    '<td width="40%" align="center" class="line_dash"><input id="time_e6" type="text" class="textBox_time" value="2359"/>  </td>'+		        
		  '</tr>'+
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><input type="checkbox" name="day7" checked /><span class="txt_module">วันเสาร์</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><input id="time_b7" type="text" class="textBox_time" value="0000" />  </td>'+		        
		    '<td width="40%" align="center" class="line_dash"><input id="time_e7" type="text" class="textBox_time" value="2359"/>  </td>'+		        
		  '</tr>'+		  
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><img src="images/ok-32.png" alt="" width="32" height="19" onclick="editDayALarmEmp();" /></td>'+
		    '<td width="40%" align="center" class="line_dash">&nbsp;</td>'+		        
		    '<td width="40%" align="center" class="line_dash">&nbsp;</td>'+		        
		  '</tr>'+		  		  
		'</table>'+
		'</fieldset>';
		showDayAlarm.innerHTML = html;
		//day1	
		//alert(txt);	
		var oRE = /<day1>(.*)<\/day1>/gi;				
		day1 = rxml(txt, oRE);			
		var cb_day1 = document.getElementsByName("day1");
		if(day1.length == 0 || day1 == "N"){
			cb_day1[0].checked = false;
		}else{
			cb_day1[0].checked = true;
		}
		//alert(txt);	
		oRE = /<time_b1>(.*)<\/time_b1>/gi;				
		time_b1 = rxml(txt, oRE);	
		if(time_b1 == "")time_b1 = "0000";
		document.getElementById("time_b1").value = time_b1;
		oRE = /<time_e1>(.*)<\/time_e1>/gi;				
		time_e1 = rxml(txt, oRE);
		if(time_e1 == "")time_e1 = "2359";
		document.getElementById("time_e1").value = time_e1;
		//day2		
		oRE = /<day2>(.*)<\/day2>/gi;				
		day2 = rxml(txt, oRE);	
		var cb_day2 = document.getElementsByName("day2");
		if(day2.length == 0 || day2 == "N"){
			cb_day2[0].checked = false;
		}else{
			cb_day2[0].checked = true;
		}	
		//alert(txt);	
		oRE = /<time_b2>(.*)<\/time_b2>/gi;				
		time_b2 = rxml(txt, oRE);		
		if(time_b2 == "")time_b2 = "0000";
		document.getElementById("time_b2").value = time_b2;
		oRE = /<time_e2>(.*)<\/time_e2>/gi;				
		time_e2 = rxml(txt, oRE);
		if(time_e2 == "")time_e2 = "2359";
		document.getElementById("time_e2").value = time_e2;
		//day3
		oRE = /<day3>(.*)<\/day3>/gi;				
		day3 = rxml(txt, oRE);				
		var cb_day3 = document.getElementsByName("day3");
		if(day3.length == 0 || day3 == "N"){
			cb_day3[0].checked = false;
		}else{
			cb_day3[0].checked = true;
		}				
		oRE = /<time_b3>(.*)<\/time_b3>/gi;				
		time_b3 = rxml(txt, oRE);		
		if(time_b3 == "")time_b3 = "0000";
		document.getElementById("time_b3").value = time_b3;
		oRE = /<time_e3>(.*)<\/time_e3>/gi;				
		time_e3 = rxml(txt, oRE);
		if(time_e3 == "")time_e3 = "2359";
		document.getElementById("time_e3").value = time_e3;
		//day4
		oRE = /<day4>(.*)<\/day4>/gi;				
		day4 = rxml(txt, oRE);				
		var cb_day4 = document.getElementsByName("day4");
		if(day4.length == 0 || day4 == "N"){
			cb_day4[0].checked = false;
		}else{
			cb_day4[0].checked = true;
		}						
		oRE = /<time_b4>(.*)<\/time_b4>/gi;				
		time_b4 = rxml(txt, oRE);		
		if(time_b4 == "")time_b4 = "0000";
		document.getElementById("time_b4").value = time_b4;
		oRE = /<time_e4>(.*)<\/time_e4>/gi;				
		time_e4 = rxml(txt, oRE);
		if(time_e4 == "")time_e4 = "2359";
		document.getElementById("time_e4").value = time_e4;
		//day5
		oRE = /<day5>(.*)<\/day5>/gi;				
		day5 = rxml(txt, oRE);				
		var cb_day5 = document.getElementsByName("day5");
		if(day5.length == 0 || day5 == "N"){
			cb_day5[0].checked = false;
		}else{
			cb_day5[0].checked = true;
		}
		
		//alert(txt);								
		oRE = /<time_b5>(.*)<\/time_b5>/gi;				
		time_b5 = rxml(txt, oRE);		
		if(time_b5 == "")time_b5 = "0000";
		document.getElementById("time_b5").value = time_b5;
		oRE = /<time_e5>(.*)<\/time_e5>/gi;				
		time_e5 = rxml(txt, oRE);
		if(time_e5 == "")time_e5 = "2359";
		document.getElementById("time_e5").value = time_e5;
		//day6
		oRE = /<day6>(.*)<\/day6>/gi;				
		day6 = rxml(txt, oRE);				
		var cb_day6 = document.getElementsByName("day6");
		if(day6.length == 0 || day6 == "N"){
			cb_day6[0].checked = false;
		}else{
			cb_day6[0].checked = true;
		}										
		oRE = /<time_b6>(.*)<\/time_b6>/gi;				
		time_b6 = rxml(txt, oRE);		
		if(time_b6 == "")time_b6 = "0000";
		document.getElementById("time_b6").value = time_b6;
		oRE = /<time_e6>(.*)<\/time_e6>/gi;				
		time_e6 = rxml(txt, oRE);
		if(time_e6 == "")time_e6 = "2359";
		document.getElementById("time_e6").value = time_e6;
		//day7
		oRE = /<day7>(.*)<\/day7>/gi;				
		day7 = rxml(txt, oRE);				
		var cb_day7 = document.getElementsByName("day7");
		if(day7.length == 0 || day7 == "N"){
			cb_day7[0].checked = false;
		}else{
			cb_day7[0].checked = true;
		}												
		oRE = /<time_b7>(.*)<\/time_b7>/gi;				
		time_b7 = rxml(txt, oRE);		
		if(time_b7 == "")time_b7 = "0000";
		document.getElementById("time_b7").value = time_b7;
		oRE = /<time_e7>(.*)<\/time_e7>/gi;				
		time_e7 = rxml(txt, oRE);
		if(time_e7 == "")time_e7 = "2359";
		document.getElementById("time_e7").value = time_e7;
		
		waiting.innerHTML = "";
		
	}
	
	function editDayALarmEmp(){
		var param = getParam();
		//alert(param);
		//list alarm	
        var session = Math.random();
        new Ajax.Request(
        "ajax_cmddayalarmemp.php?session=" + session +'&emp_id=' + emp_id + "&alarm_num=" + alarm_num + "&" + param + "&action=edit" ,			// url
        { asynchronous: true,			// default is true
            method: "get",				// default is post
            onSuccess: function(request) {
                rtnEditDayALarmEmp(request.responseText);
            }
        });	
		
		waiting.innerHTML = '<img src="images/loading1.gif"/> <span class="required">process...</span>';        				
	
	}
	
	function rtnEditDayALarmEmp(){
		waiting.innerHTML = '<span class="required">sucess...</span>';   
		showALarm(emp_id, emp_name);     					
	}
	
	//#################################### end fucntion manage Alarm #########################	
	
</script>
<div id="content">
	<div class="post">		
		<h2>แสดงข้อมูลเกี่ยวกับ พนักงาน</h2>
		<div class="entry">
			<div id="view">{VIEW_EMPNAME}</div>
		</div>
	</div>
	<div class="post"><div id="waiting"></div>					
		<div style="visibility:hidden" id="view_header"><h2>จัดการข้อมูลเกี่ยวกับ พนักงาน</h2></div>
		<div class="entry">							
			<div id="emp_add"></div>	
			<!--<div id="test1"></div>	-->
		</div>		
	</div>
</div>